<html>
<head><meta charset="utf-8"><title>Creating Files from an Assist · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html">Creating Files from an Assist</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203083505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203083505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203083505">(Jul 07 2020 at 09:38)</a>:</h4>
<p>I'm trying to implement an assist that extracts inline modules to a a file. ( <a href="https://github.com/rust-analyzer/rust-analyzer/issues/5054">https://github.com/rust-analyzer/rust-analyzer/issues/5054</a> )</p>
<p><span class="user-mention" data-user-id="133169">@matklad</span> referenced two starting points, but I'm bumping up against some limitations because assists currently don't have the machinery for adding new files.</p>
<p>I have an idea how to implement it, but I thought I'd ask if this sounds reasonable first:</p>
<ul>
<li>extend <code>ra_ide_db::source_change::FileSystemEdit::CreateFile</code>with a <code>contents: Option&lt;String&gt;</code> </li>
</ul>
<p>For LSP this  would be expanded to 2 separate document changes in <code>snippet_workspace_edit()</code> ( <code>lsp_types::CreateFile</code> + a edit with the initial content )</p>
<ul>
<li>
<p>change <code>AssistBuilder</code> to hold a full <code>SourceChange</code> instead of <code>Vec&lt;SourceFileEdit&gt;</code></p>
</li>
<li>
<p>add <code>AssistBuilder::create_file(&amp;mut self, relative_path: String, contents: String)</code>, witht the relative path anchored at <code>AssistBuilder::file_id</code></p>
</li>
</ul>



<a name="203083640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203083640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203083640">(Jul 07 2020 at 09:40)</a>:</h4>
<p>Yup, these all sounds resonnable</p>



<a name="203083701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203083701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203083701">(Jul 07 2020 at 09:41)</a>:</h4>
<p>The only bit I am unusre about is the last one, about <code>create_file</code>:</p>
<ul>
<li>It's not super clear how to represent "relative to a file" paths in rust-analyzer (we do this in an ad hoc manner at the moment)</li>
<li>The fact that there's "current" file in assist builder might be an accident of historical designt</li>
</ul>



<a name="203083709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203083709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203083709">(Jul 07 2020 at 09:41)</a>:</h4>
<p>but I don't have any strictly better proposals of hand</p>



<a name="203083786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203083786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203083786">(Jul 07 2020 at 09:42)</a>:</h4>
<p><span class="user-mention" data-user-id="214681">@theduke</span> I guess one thing though is that let's <em>first</em> refactor assist to hold <code>SourceChange</code> and send that as a PR without functional changes.</p>



<a name="203083800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203083800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203083800">(Jul 07 2020 at 09:42)</a>:</h4>
<p>Than it would be easier to review file addition API</p>



<a name="203084027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203084027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203084027">(Jul 07 2020 at 09:45)</a>:</h4>
<p>Can do, but I just did that and it's a tiny diff</p>
<div class="codehilite"><pre><span></span><code><span class="gh">diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs</span>
<span class="gh">index 3640bb4d2..f34c6dfde 100644</span>
<span class="gd">--- a/crates/ra_assists/src/assist_context.rs</span>
<span class="gi">+++ b/crates/ra_assists/src/assist_context.rs</span>
<span class="gu">@@ -7,7 +7,7 @@ use hir::Semantics;</span>
 use ra_db::{FileId, FileRange};
 use ra_fmt::{leading_indent, reindent};
 use ra_ide_db::{
<span class="gd">-    source_change::{SourceChange, SourceFileEdit},</span>
<span class="gi">+    source_change::{SourceChange, SourceFileEdit, FileSystemEdit},</span>
     RootDatabase,
 };
 use ra_syntax::{
<span class="gu">@@ -176,7 +176,7 @@ pub(crate) struct AssistBuilder {</span>
     edit: TextEditBuilder,
     file_id: FileId,
     is_snippet: bool,
<span class="gd">-    edits: Vec&lt;SourceFileEdit&gt;,</span>
<span class="gi">+    change: SourceChange,</span>
 }

 impl AssistBuilder {
<span class="gu">@@ -185,7 +185,7 @@ impl AssistBuilder {</span>
             edit: TextEditBuilder::default(),
             file_id,
             is_snippet: false,
<span class="gd">-            edits: Vec::new(),</span>
<span class="gi">+            change: SourceChange::default(),</span>
         }
     }

<span class="gu">@@ -197,8 +197,8 @@ impl AssistBuilder {</span>
         let edit = mem::take(&amp;mut self.edit).finish();
         if !edit.is_empty() {
             let new_edit = SourceFileEdit { file_id: self.file_id, edit };
<span class="gd">-            assert!(!self.edits.iter().any(|it| it.file_id == new_edit.file_id));</span>
<span class="gd">-            self.edits.push(new_edit);</span>
<span class="gi">+            assert!(!self.change.source_file_edits.iter().any(|it| it.file_id == new_edit.file_id));</span>
<span class="gi">+            self.change.source_file_edits.push(new_edit);</span>
         }
     }

<span class="gu">@@ -265,10 +265,10 @@ impl AssistBuilder {</span>

     fn finish(mut self) -&gt; SourceChange {
         self.commit();
<span class="gd">-        let mut res: SourceChange = mem::take(&amp;mut self.edits).into();</span>
<span class="gi">+        let mut change = mem::take(&amp;mut self.change);</span>
         if self.is_snippet {
<span class="gd">-            res.is_snippet = true;</span>
<span class="gi">+            change.is_snippet = true;</span>
         }
<span class="gd">-        res</span>
<span class="gi">+        change</span>
     }
 }
</code></pre></div>



<a name="203084108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203084108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203084108">(Jul 07 2020 at 09:46)</a>:</h4>
<blockquote>
<p>Can do, but I just did that and it's a tiny diff</p>
</blockquote>
<p>The tinyer the diff, the merrier  I am :-)</p>



<a name="203084150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203084150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203084150">(Jul 07 2020 at 09:46)</a>:</h4>
<p>hehe, alright I'll open a separate PR then</p>



<a name="203086405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203086405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203086405">(Jul 07 2020 at 10:21)</a>:</h4>
<p>Should I also do two separate PRs for the create file changes and the actual new assist?</p>



<a name="203086647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203086647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203086647">(Jul 07 2020 at 10:25)</a>:</h4>
<p>Either way is fine</p>



<a name="203099157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203099157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203099157">(Jul 07 2020 at 13:07)</a>:</h4>
<p>How would I get the current file name in an assist?<br>
As in, somehow turn a <code>FileId</code> into a path</p>
<p>I've been jumping around the code for a while and can't really find a way</p>
<p>I need it to determine the target path</p>
<p>eg for  <code>mod x{}</code> :</p>
<ul>
<li>inside <code>mod.rs</code> =&gt; <code>./x.rs</code></li>
<li>inside <code>some_parent.rs</code> =&gt; <code>./some_parent/x.rs</code></li>
</ul>



<a name="203102240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203102240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203102240">(Jul 07 2020 at 13:32)</a>:</h4>
<p>Seems like that would require a quite a lot of new plumbing since it needs a new method on: </p>
<ul>
<li><code>FileLoader</code></li>
<li><code>FileLoaderDelegate</code></li>
<li><code>SourceDatabaseExt</code></li>
<li><code>SourceDatabase</code></li>
</ul>
<p>Unless I'm missing some existing helper method somewhere (which I probably am)</p>



<a name="203103268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203103268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203103268">(Jul 07 2020 at 13:40)</a>:</h4>
<p>So, the general answer that you don't :)</p>



<a name="203103299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203103299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203103299">(Jul 07 2020 at 13:40)</a>:</h4>
<p>We deliberatelly don't expose full file paths to internals</p>



<a name="203103335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203103335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203103335">(Jul 07 2020 at 13:41)</a>:</h4>
<p>so that we don't accidently rely on files being on disk or something like that</p>



<a name="203103567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203103567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203103567">(Jul 07 2020 at 13:42)</a>:</h4>
<p>We have <code>is_mod_rs</code> on <code>Module</code> for this, and you can look at the <code>Module</code>'s name. I think that should be enough</p>



<a name="203111564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203111564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203111564">(Jul 07 2020 at 14:44)</a>:</h4>
<p>Makes sense. Yeah is_mod_rs is all I need.</p>



<a name="203112584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203112584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203112584">(Jul 07 2020 at 14:52)</a>:</h4>
<blockquote>
<p>so that we don't accidently rely on files being on disk </p>
</blockquote>
<p>To clarify, this is not about "files phisicaly being stored on a hard drive", but about "path represents an inode". I can imagine  some remote analysis scenarios, where files are purely virtual, and don't correspond to an existing FS at all. This might be overenginering though, but maybe not :)</p>



<a name="203113525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203113525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203113525">(Jul 07 2020 at 14:59)</a>:</h4>
<p>No it makes sense to have an abstraction from complete files<br>
also  when considering more complicated refactorings</p>



<a name="203113610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203113610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203113610">(Jul 07 2020 at 15:00)</a>:</h4>
<p>I'm thinking about how to test the new assist</p>



<a name="203113657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203113657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203113657">(Jul 07 2020 at 15:00)</a>:</h4>
<p>Good question!</p>



<a name="203113678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203113678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203113678">(Jul 07 2020 at 15:00)</a>:</h4>
<p>right now, all the tests simply create a mock file, manually get the source code, apply the assist and that's it</p>



<a name="203113718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203113718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203113718">(Jul 07 2020 at 15:01)</a>:</h4>
<p>You can create mulitfile fixtures</p>



<a name="203113752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203113752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203113752">(Jul 07 2020 at 15:01)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/fix_visibility.rs#L510-L524">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/fix_visibility.rs#L510-L524</a></p>



<a name="203113773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203113773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203113773">(Jul 07 2020 at 15:01)</a>:</h4>
<p>But I think you can assert only a single file</p>



<a name="203114042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203114042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203114042">(Jul 07 2020 at 15:03)</a>:</h4>
<p>yeah, and the <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/tests.rs#L84">test code</a> only applies a single edit manually</p>



<a name="203114310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203114310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203114310">(Jul 07 2020 at 15:04)</a>:</h4>
<p>I guess <code>rename</code> would also touch and test multiple files, but that doesn't seem to be in <code>ra_assists::handlers</code> ?</p>



<a name="203114424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203114424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203114424">(Jul 07 2020 at 15:05)</a>:</h4>
<p>ah, <code>ra_ide::references::rename</code></p>



<a name="203114859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203114859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203114859">(Jul 07 2020 at 15:08)</a>:</h4>
<p>The <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/references/rename.rs#L280">rename check</a> does more or less the same thing</p>



<a name="203115136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203115136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203115136">(Jul 07 2020 at 15:10)</a>:</h4>
<p>but it would be really nice to have something like <code>SourceChange::apply(db) -&gt; RootDatabase</code></p>



<a name="203115179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203115179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> theduke <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203115179">(Jul 07 2020 at 15:10)</a>:</h4>
<p>or whatever the right target would be</p>



<a name="203115393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203115393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203115393">(Jul 07 2020 at 15:12)</a>:</h4>
<p>I think that should be a testing utility, which returns a set of modified files (so that you don't need to compare files which are not changed)</p>



<a name="203115422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Creating%20Files%20from%20an%20Assist/near/203115422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Creating.20Files.20from.20an.20Assist.html#203115422">(Jul 07 2020 at 15:12)</a>:</h4>
<p>And, in tests, I think you should have access to file paths</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>